'use strict';
import React,{Component} from 'react';
import Header from '../common/header';
import Util from '../common/util';
import Toast from '../common/ToastUtil'
import * as URLconstant from '../constant/URLconstant'
import GoodsIndex from '../goods/goodsIndex'
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    ListView,
    StyleSheet
} from 'react-native';
export default class userHistory extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
           goodsList:null
        };
      }

    componentDidMount() {
        this.getHistory()
    }

      getHistory(){
          let url = URLconstant.MY_HISTORY
          let datakey=[]
          let params = this.props.route.params
          datakey['user_id']=params.user_id
          Util.get(url,datakey,this.getHistorySuc.bind(this),this.errorCallback.bind(this))
      }
    getHistorySuc(datas){
        if(datas.status==0){
            this.setState({
                goodsList:datas.data
            })
        }else{
            this.setState({
                goodsList:[]
            })
        }
    }
    errorCallback(err){

    }

      render(){
          let goodsList = this.state.goodsList
          return(
              <View style={{flex:1,backgroundColor:'#f0f0f0'}}>
                  <Header navigation={this.props.navigation} title={'我的足迹'}/>
                  {
                      goodsList==null?
                          <View style={{flex:1,}}>
                              {Util.loading()}
                          </View>:
                          <View style={{flex:1}}>
                              {
                                  goodsList.length==0?
                                      <View style={{flex:1,alignItems:'center',justifyContent:'center'}}>
                                          <Text>没有浏览记录</Text>
                                      </View>
                                      :
                                      <View style={styles.goods_list_view}>
                                          {
                                              goodsList.map((item,index)=>{
                                                  return(
                                                      <View key={index} style={styles.goods_item}>
                                                          <Image
                                                              source={{uri:item.default_image}}
                                                              resizeMode={'cover'}
                                                              style={styles.default_image}
                                                          />
                                                          <View style={styles.goods_txt_view}>
                                                              <Text style={{fontSize:14,color:"#333",marginBottom:5}}>{item.goods_name}</Text>
                                                              <Text style={{fontSize:14,color:"#f00"}}>¥{item.price}</Text>
                                                          </View>
                                                      </View>
                                                  )
                                              })
                                          }
                                      </View>
                              }
                          </View>
                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    goods_list_view:{
        flexDirection:'row',
        alignItems:'center',
        justifyContent:'space-between',
        padding:10,
        flexWrap:'wrap'
    },
    goods_item:{
        width:(Util.size.width-30)/2,
        marginBottom:10
    },
    default_image:{
        width:(Util.size.width-30)/2,
        height:(Util.size.width-30)/2,
    },
    goods_txt_view:{
        padding:10,
        backgroundColor:"#fff"
    }
})